package com.ly.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hibernate 校验工具类
 */
public class ValidUtils {

    /**
     *
     * @param result
     * @return
     */
    public static Map<String,String> getErrors(BindingResult result) {
        Map<String,String> map = new HashMap<>();
        List<FieldError> errorList = result.getFieldErrors();
        for ( FieldError error : errorList ) {
            String field = error.getField();
            String message = error.getDefaultMessage();
            map.put(field,message);
        }
        return  map;
    }
}
